let DateUtils = {
    /**
     * 获取当前时间毫秒数
     */
    getCurrentMsTime: function () {
        let myDate = new Date();
        return myDate.getTime();
    },
    /**
     * 毫秒转时间格式
     */
    longMsTimeConvertToDateTime: function (time) {
        let myDate = new Date(time);
        return this.formatterDateTime(myDate);
    },

    /**
     * 毫秒转时间格式 不含时分秒
     */
    longMsTimeConvertToDateTime2: function (time) {
        let myDate = new Date(time);
        return this.formatterDateTime2(myDate);
    },
    /**
     * 时间格式转毫秒
     */
    dateToLongMsTime: function (date) {
        let myDate = new Date(date);
        return myDate.getTime();
    },
    /**
     * 格式化日期（不含时间）
     */
    formatterDateNoTime: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1))
            + "-"// "月"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate());
    },
    /**
     * 格式化日期（不含时间不含日）
     */
    formatterDateNoDayNoTime: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1));
    },
    /**
     * 格式化日期（含时间"00:00:00"）
     */
    formatterDate2: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1))
            + "-"// "月"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate()) + " " + "00:00:00";
    },
    /**
     * 格式化日期（含时间"23:59:59"）
     */
    formatterDate3: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1))
            + "-"// "月"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate()) + " " + "23:59:59";
    },
    /**
     * 格式化去日期（含时间）
     */
    formatterDateTime: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1))
            + "-"// "月"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate())
            + " "
            + (date.getHours() < 10 ? "0" + date.getHours() : date
                .getHours())
            + ":"
            + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                .getMinutes())
            + ":"
            + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                .getSeconds());
    },

    /**
     * 格式化去日期（不含时间）
     */
    formatterDateTime2: function (date) {
        return date.getFullYear()
            + "-"// "年"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1))
            + "-"// "月"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate());
    },
    /**
     * 时间比较{结束时间大于开始时间}
     */
    compareDateEndTimeGTStartTime: function (startTime, endTime) {
        return ((new Date(endTime.replace(/-/g, "/"))) > (new Date(
            startTime.replace(/-/g, "/"))));
    },
    /**
     * 验证开始时间合理性{开始时间不能小于当前时间{X}个月}
     */
    compareRightStartTime: function (month, startTime) {
        let now = formatterDayAndTime(new Date());
        let sms = new Date(startTime.replace(/-/g, "/"));
        let ems = new Date(now.replace(/-/g, "/"));
        let tDayms = month * 30 * 24 * 60 * 60 * 1000;
        let dvalue = ems - sms;
        return dvalue <= tDayms;

    },
    /**
     * 验证开始时间合理性{结束时间不能小于当前时间{X}个月}
     */
    compareRightEndTime: function (month, endTime) {
        let now = formatterDayAndTime(new Date());
        let sms = new Date(now.replace(/-/g, "/"));
        let ems = new Date(endTime.replace(/-/g, "/"));
        let tDayms = month * 30 * 24 * 60 * 60 * 1000;
        let dvalue = sms - ems;
        return dvalue <= tDayms;

    },
    /**
     * 验证开始时间合理性{结束时间与开始时间的间隔不能大于{X}个月}
     */
    compareEndTimeGTStartTime: function (month, startTime, endTime) {
        let sms = new Date(startTime.replace(/-/g, "/"));
        let ems = new Date(endTime.replace(/-/g, "/"));
        let tDayms = month * 30 * 24 * 60 * 60 * 1000;
        let dvalue = ems - sms;
        return dvalue <= tDayms;

    },
    /**
     * 获取最近几天[开始时间和结束时间值,时间往前推算]
     */
    getRecentDaysDateTime: function (day) {
        let dayMSTime = day * 24 * 60 * 60 * 1000;
        let yesterdayDateSMSTime = this.getCurrentMsTime() - dayMSTime;
        let startTime = this.longMsTimeConvertToDateTime(yesterdayDateSMSTime);
        let pastDate = this.formatterDate2(new Date(startTime));
        let nowDate = this.formatterDate2(new Date());
        return {
            startTime: pastDate,
            endTime: nowDate
        };
    },
    /**
     * 获取今天[开始时间和结束时间值]
     */
    getTodayDateTime: function () {
        let daymsTime = 24 * 60 * 60 * 1000;
        let tomorrowDateSMSTime = this.getCurrentMsTime() + daymsTime;
        let currentTime = this.longMsTimeConvertToDateTime(this.getCurrentMsTime());
        let tomorrowTime = this.longMsTimeConvertToDateTime(tomorrowDateSMSTime);
        let nowDate = this.formatterDate2(new Date(currentTime));
        let tomorrowDate = this.formatterDate2(new Date(tomorrowTime));
        return {
            startTime: nowDate,
            endTime: tomorrowDate
        };
    },
    /**
     * 获取明天[开始时间和结束时间值]
     */
    getTomorrowDateTime: function () {
        let daymsTime = 24 * 60 * 60 * 1000;
        let tomorrowDateTime = this.getCurrentMsTime() + daymsTime;
        let tomorrowTime = this.longMsTimeConvertToDateTime(tomorrowDateTime);
        let theDayAfterTomorrowDatsmsTime = this.getCurrentMsTime() + (2 * daymsTime);
        let theDayAfterTomorrowTime = this.longMsTimeConvertToDateTime(theDayAfterTomorrowDatsmsTime);
        let pastDate = this.formatterDate2(new Date(tomorrowTime));
        let nowDate = this.formatterDate2(new Date(theDayAfterTomorrowTime));
        return {
            startTime: pastDate,
            endTime: nowDate
        };
    },
    /**
     * 获取本月开始日期
     */
    getMonthStartDate: function () {
        let now = new Date();                    //当前日期
        let nowMonth = now.getMonth();           //当前月
        let nowYear = now.getYear();             //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;  //
        let getMonthStartDate = new Date(nowYear, nowMonth, 1);
        return this.formatterDateNoTime(getMonthStartDate);
    },
    /**
     * 获取本周开始日期
     */
    //获得本周的开始日期
    getWeekStartDate: function () {
        let now = new Date();                    //当前日期
        let nowMonth = now.getMonth();           //当前月
        let nowDayOfWeek = now.getDay();         //今天本周的第几天
        let nowDay = now.getDate();              //当前日
        let nowYear = now.getYear();             //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;  //
        let getWeekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1);
        return this.formatterDateNoTime(getWeekStartDate);
    },
    /**
     * 获取当前年月
     */
    getNowYearMonth: function () {
        let now = new Date();                    //当前日期
        let nowMonth = now.getMonth();           //当前月
        let nowYear = now.getYear();             //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;  //
        let getMonths = new Date(nowYear, nowMonth);
        return this.formatterDateNoDayNoTime(getMonths);
    },

    /**
     * 获取上个月
     */
    getLastYearMonth: function () {
        let now = new Date();                    //当前日期
        let nowMonth = now.getMonth() - 1;           //当前月
        let nowYear = now.getYear();             //当前年
        if (nowMonth === 0) {
            nowMonth = 12;
            nowYear = nowYear - 1;
        }
        nowYear += (nowYear < 2000) ? 1900 : 0;  //
        let getMonths = new Date(nowYear, nowMonth);
        return this.formatterDateNoDayNoTime(getMonths);
    }
}


// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {
    let o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (let k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


//日期加上天数得到新的日期
//dateTemp 需要参加计算的日期，days要添加的天数，返回新的日期，dateTemp格式：YYYY-MM-DD
function getNewDate(dateTemp, days) {
    dateTemp = dateTemp.split("-");
    let nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式
    let millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
    let rDate = new Date(millSeconds);
    let year = rDate.getFullYear();
    let month = rDate.getMonth() + 1;
    if (month < 10) month = "0" + month;
    let date = rDate.getDate();
    if (date < 10) date = "0" + date;
    return (year + "-" + month + "-" + date);
}